/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2011 Bull S.A.S.
 * Contact: jonas-team@ow2.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 *
 * --------------------------------------------------------------------------
 * $Id: ProcessorAlarmCreator.java 444 2011-08-16 16:24:00Z guillaume.sauthier $
 * --------------------------------------------------------------------------
 */


package org.osami.gateway.mediator.alarm.internal;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import fr.liglab.adele.cilia.CiliaException;
import fr.liglab.adele.cilia.Data;
import org.osami.gateway.alarm.AlarmImpl;
import org.osami.gateway.alarm.IAlarm;

/**
 * A {@code ProcessorAlarmCreator} is responsible to transform a Data (coming
 * from EventAdmin) into a real IAlarm instance.
 *
 * @author Guillaume Sauthier
 */
public class ProcessorAlarmCreator {

    public List<Data> process(List<Data> input) {
        List<Data> result = new ArrayList<Data>();

        if (input != null) {

            // Transform each input Data into an Alarm
            for (Data data : input) {

                String identifier = (String) data.getProperty(IAlarm.ID_PROPERTY);
                Date date = (Date) data.getProperty(IAlarm.DATE_PROPERTY);
                String message = (String) data.getProperty(IAlarm.MESSAGE_PROPERTY);
                String severity = (String) data.getProperty(IAlarm.SEVERITY_PROPERTY);

                // Unused attributes ATM
                //String source = (String) data.getProperty("source");
                //String type = (String) data.getProperty("type");
                //Double threshold = (Double) data.getProperty("threshold");
                //Double value = (Double) data.getProperty("value");

                IAlarm alarm = new AlarmImpl(identifier, date, message, IAlarm.Severity.valueOf(severity));
                result.add(new Data(alarm));
            }
        }

        return result;
    }
}
